import json

def generate_configs():
    # Read configuration from JSON file
    with open('./config.json', 'r') as f:
        config = json.load(f)
    
    input_shape = config['input_shape']
    output_shape = config['output_shape']
    dtype = config['dtype']
    
    # Generate C++ header file
    with open('../shape_config.h', 'w') as f:
        f.write('#ifndef SHAPE_CONFIG_H\n')
        f.write('#define SHAPE_CONFIG_H\n\n')
        f.write(f'const int INPUT_SHAPE[] = {{{input_shape[0]}, {input_shape[1]}}};\n')
        f.write(f'const int INPUT_SHAPE_SIZE = {len(input_shape)};\n\n')
        f.write(f'const int OUTPUT_SHAPE[] = {{{output_shape[0]}, {output_shape[1]}}};\n')
        f.write(f'const int OUTPUT_SHAPE_SIZE = {len(output_shape)};\n\n')
        f.write('#endif // SHAPE_CONFIG_H\n')
    
    # Generate Python config file
    with open('./shape_config.py', 'w') as f:
        f.write(f'INPUT_SHAPE = {input_shape}\n')
        f.write(f'OUTPUT_SHAPE = {output_shape}\n')
        f.write(f'DTYPE = "{dtype}"\n')

generate_configs()
